


import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:textfluttertimer/test_provider/list_model.dart';

class SelectListWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SelectListState();
  }

}



class _SelectListState extends State<SelectListWidget>{

  List<Person> list = [];

  @override
  void initState() {
    list.add(new Person(name: "张三", age: 19, count: 1));
    list.add(new Person(name: "李四", age: 20, count: 2));
    list.add(new Person(name: "王五", age: 21, count: 3));
    list.add(new Person(name: "赵六", age: 22, count: 4));
    list.add(new Person(name: "田七", age: 23, count: 5));

    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemBuilder: (content,index){
          return Row(
            children: [
              Text("name: ${list[index].name}-----"),
              Text("age: ${list[index].age}-----"),
              Text("count: ${list[index].count}-----"),
              CountWidget(index: index,item:list[index]),
            ],
          );
        },
      itemCount: list.length,
    );
  }

}


class CountWidget extends StatelessWidget {

  int index;
  Person item;
  CountWidget({super.key,required this.index,required this.item});

  @override
  Widget build(BuildContext context) {
    return Selector<ListPersion,List<Person>>(
      selector: (context,model){
        return model.myList.toList();
      },
      builder: (context,model,child){
        return ListView.builder(
            itemCount: model.length,
            itemBuilder: (context,index){
              return Text(model[index].name);
            });
      },
    );

  }

}


class Person{
  String name;
  int age;
  int count;
  Person({required this.name,required this.age,required this.count});
}